from django.shortcuts import render
from django.http import HttpResponse
from listings.choices import price_choices, bedroom_choices, state_choices   #编写引入语句

from listings.models import Listing
from realtors.models import Realtor  #实现关于页面中的动态数据的呈现。


def index(request):
    listings = Listing.objects.order_by(
        '-list_date').filter(is_published=True)[:3]

    context = {
        'listings': listings,
        'state_choices': state_choices,   #把这三个 Dictionary 添加到 context 中，随后传入到网页模板中。
        'bedroom_choices': bedroom_choices,
        'price_choices': price_choices,
    }

    return render(request,'pages/index.html', context)


def about(request):
    #第一个是最下面的团队部分
    realtors = Realtor.objects.order_by('-hire_date')

    #第二个是页面右方的本月销售冠军
    mvp_realtors = Realtor.objects.all().filter(is_mvp=True)

    context = {
        'realtors': realtors,
        'mvp_realtors': mvp_realtors
    }

    return render(request,'pages/about.html',context)
